/*********************
* Author:Dzlua
* QQ:505544956
* time:2016/12/03
*/
#include "LuaTileLayout.h"
#include "../../utilities/Log.h"

#ifdef EDUI_USE_LUAPLUS

EDUI_NAMESPACE_BEGIN

#define CObjPtr (TileLayout::ToTileLayout(m_cobj))

void* LuaTileLayout::GetInterface(void* data)
{
    if (!data) return 0;
    LuaTileLayout* tileLayout = new LuaTileLayout((TileLayout*)data);
#ifdef EDUI_TEST_NEW_DELETE
    ++m_newdeleteNum;
    Log("[LuaTileLayout] new LuaTileLayout : %d, %d", tileLayout, data);
#endif
    return tileLayout;
}

void LuaTileLayout::Release()
{
#ifdef EDUI_TEST_NEW_DELETE
    --m_newdeleteNum;
    Log("[LuaTileLayout] delete LuaTileLayout : %d, %d, %s", this, m_cobj, this->GetName());
#endif
    delete this;
}

LuaTileLayout::LuaTileLayout(TileLayout* tileLayout) : LuaContainer(tileLayout)
{}

LuaTileLayout::~LuaTileLayout()
{}

//----------------------------------------//

void LuaTileLayout::SetItemSize(int w, int h)
{
    CObjPtr->SetItemSize(w, h);
}

int LuaTileLayout::GetItemSize(LuaState *L)
{
    Size sz = CObjPtr->GetItemSize();
    LuaObject obj = LuaBaseNS::ToLuaObj(L, &sz);
    obj.Push(L);
    return 1;
}

void LuaTileLayout::SetColumns(int columns)
{
    CObjPtr->SetColumns(columns);
}

int  LuaTileLayout::GetColumns()
{
    return CObjPtr->GetColumns();
}

//----------------------------------------//

void LuaTileLayout::Register(LuaState *L)
{
    LuaObject obj = LuaHelperNS::AddToMetas(L, "TileLayout", "Container");
    obj.SetObject("__index", obj);
    obj.RegisterDirect("__NewCObj__", &LuaTileLayout::GetInterface);

    obj.RegisterObjectDirect("SetItemSize", (LuaTileLayout*)0, &LuaTileLayout::SetItemSize);
    obj.RegisterObjectFunctor("GetItemSize", &LuaTileLayout::GetItemSize);
    obj.RegisterObjectDirect("SetColumns", (LuaTileLayout*)0, &LuaTileLayout::SetColumns);
    obj.RegisterObjectDirect("GetColumns", (LuaTileLayout*)0, &LuaTileLayout::GetColumns);
}

#undef CObjPtr

EDUI_NAMESPACE_END

#endif